package com.ruoyi.comment.controller;

import com.ruoyi.comment.domain.Theme;
import com.ruoyi.comment.service.IThemeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 测评题目表Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/comment/theme")
public class ThemeController extends BaseController
{
    @Autowired
    private IThemeService themeService;

    /**
     * 查询测评题目表列表
     */
    @PreAuthorize("@ss.hasPermi('comment:theme:list')")
    @GetMapping("/list")
    public TableDataInfo list(Theme theme)
    {
        startPage();
        List<Theme> list = themeService.selectThemeList(theme);
        return getDataTable(list);
    }

    /**
     * 导出测评题目表列表
     */
    @PreAuthorize("@ss.hasPermi('comment:theme:export')")
    @Log(title = "测评题目表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Theme theme)
    {
        List<Theme> list = themeService.selectThemeList(theme);
        ExcelUtil<Theme> util = new ExcelUtil<Theme>(Theme.class);
        util.exportExcel(response, list, "测评题目表数据");
    }

    /**
     * 获取测评题目表详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:theme:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(themeService.selectThemeById(id));
    }

    /**
     * 新增测评题目表
     */
    @PreAuthorize("@ss.hasPermi('comment:theme:add')")
    @Log(title = "测评题目表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Theme theme)
    {
        return toAjax(themeService.insertTheme(theme));
    }

    /**
     * 修改测评题目表
     */
    @PreAuthorize("@ss.hasPermi('comment:theme:edit')")
    @Log(title = "测评题目表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Theme theme)
    {
        return toAjax(themeService.updateTheme(theme));
    }

    /**
     * 删除测评题目表
     */
    @PreAuthorize("@ss.hasPermi('comment:theme:remove')")
    @Log(title = "测评题目表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(themeService.deleteThemeByIds(ids));
    }
}
